module App::Items
    class Client < Qt::StandardItem
        attr_reader :tid, :name

        def self.create(model, name)
            ret = model.toggl.newClient name
            togglclient = ret["content"].first
            new(togglclient)
        end

        def initialize(togglclient)
            super()

            @tid = togglclient["id"]
            @name = togglclient["name"]

            setEditable false
            showName
        end

        def destroy
            model.toggl.deleteClient self
            model.deleteClient self
        end

        def save
            model.toggl.setClient self
        end

        private
        def showName()
            setText @name.to_s
        end
    end
end
